'use strict';
/**
 * Created by FreezeSoul on 2015/11/3.
 */
define([
        'angular',
        'jquery',
        'jQueryPerfectScroll',
        'app/modules/page/define'
    ],
    function (angular, $) {
        angular.module('ad.page')
            .directive('scrollContainer', ['$timeout', function ($timeout) {
                return {
                    scope: {
                        size: '='
                    },
                    link: function ($scope, $elm, $attrs, $ctrl) {
                        $($elm).perfectScrollbar();
                        $scope.$watch('size', function (newValue, oldValue) {
                            if (newValue) {
                                var width = newValue.split('X')[0];
                                var height = newValue.split('X')[1];
                                var $pageDesigner = $($elm).find("#page-designer");
                                if (width > 0) {
                                    $pageDesigner.width(width);
                                } else {
                                    $pageDesigner.css('width', '100%');
                                }
                                if (height > 0) {
                                    $pageDesigner.height(height);
                                } else {
                                    $pageDesigner.css('height', '100%');
                                }
                                $($elm).perfectScrollbar('update');
                                $timeout(function () {
                                    if ($scope.$parent.layoutPlugin) {
                                        $scope.$parent.layoutPlugin.resize();
                                    }
                                }, 100);
                            }
                        }, true);
                    }
                };
            }]);
    });